<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\MusicParagraphSentence;
use Illuminate\Http\Request;

class MusicParagraphSentenceController extends Controller
{
    public function index(Request $request)
    {
        // 段落ID
        $musicParagraphId = $request->input("id");

        $models = MusicParagraphSentence::where("music_paragraph_id", $musicParagraphId)
            ->orderBy("music_paragraph_sentences_order", "asc")
            ->get();

        return view("admin.musicParagraphSentence.index", [
            "models" => $models,
            "musicParagraphId" => $musicParagraphId,
            "pageName" => "音乐段落句子列表",
        ]);
    }

    public function create(Request $request)
    {
        $musicParagraphId = $request->input("musicParagraphId");

        return view("admin.musicParagraphSentence.create", [
            "pageName" => "添加音乐段落句子",
            "musicParagraphId" => $musicParagraphId,

        ]);
    }

    public function save(Request $request)
    {
        $model = new MusicParagraphSentence();
        $model->music_paragraph_id = $request->post("music_paragraph_id");
        $model->music_paragraph_sentences_name = $request->post("music_paragraph_sentences_name");
        $model->music_paragraph_sentences_file = $request->post("music_paragraph_sentences_file");
        $model->music_paragraph_sentences_order = $request->post("music_paragraph_sentences_order");
        $model->save();
        return redirect()->route("adminMusicParagraphSentenceIndex", ["id" => $model->music_paragraph_id]);

    }

    public function delete(Request $request)
    {
        $id = $request->input("id");
        $musicParagraphSentence = MusicParagraphSentence::find($id);
        $musicParagraphSentence->delete();
        return redirect()->route("adminMusicParagraphSentenceIndex", ["id" => $musicParagraphSentence->music_paragraph_id]);


    }

    public function edit(Request $request)
    {
        $id = $request->input("id");
        $model = MusicParagraphSentence::find($id);

        return view("admin.musicParagraphSentence.edit", [
            "model" => $model,
            "pageName" => "编辑音乐段落句子",

        ]);
    }
    public function update(Request $request)
    {
        $id = $request->input("id");
        $model = MusicParagraphSentence::find($id);
        $model->music_paragraph_sentences_name = $request->post("music_paragraph_sentences_name");
        $model->music_paragraph_sentences_file = $request->post("music_paragraph_sentences_file");
        $model->music_paragraph_sentences_order = $request->post("music_paragraph_sentences_order");
        $model->save();
        return redirect()->route("adminMusicParagraphSentenceIndex", ["id" => $model->music_paragraph_id]);

    }
}
